@extends('layout.master')

@section('title','管理员信息')

@section('css')
    @parent
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.css') }}" rel="stylesheet">
    <style>
        .form-material .form-group.stySelect {
            overflow: visible;
        }

        .form-material button.form-control {
            padding: .8rem 25px .8rem 1.2rem;
            border: 1px solid #e4e7ea;
        }

        .dropify-wrapper {
            border: 0;
        }
    </style>
@endsection
@section('main')
    <div class="row">
        <div class="col-lg-12 col-md-12">
            <div class="white-box">
                <form class="form-horizontal form-material" id="editadmin" method="post"  enctype="multipart/form-data">
                    <input type="hidden" value="{{ $admin->id }}" id="adminid">
                    <div class="row">
                        <div class="col-md-7">
                            <div class="form-group">
                                <label class="col-md-12">用户名</label>
                                <div class="col-md-12">
                                    <input type="text" value="{{ $admin->name }}" name="name"
                                           class="form-control form-control-line">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-12">修改安全密码</label>
                        <input type="password" name="password" class="form-control form-control-line">
                    </div>
                    <div class="row">
                        <div class="col-md-4 form-group stySelect">
                            <label class="col-md-12">用户权限</label>
                            @foreach(App\Role::all() as $value)
                                <label class="btn btn-default" type="button">
                                    <input type="checkbox" {{ $admin->hasRole($value->name) ? 'checked' : '' }} name="roles[]" value="{{ $value->id }}">{{ $value->display_name }}
                                </label><br>
                            @endforeach
                        </div>

                        <div class="col-md-2 form-group">
                            <label class="col-md-12">创建时间</label>
                            <input type="text" value="{{ date('Y-m-d', $admin->created_at) }}" class="form-control form-control-line"
                                   disabled>
                        </div>
                        <div class="col-md-2 form-group">
                            <label class="col-md-12">更新时间</label>
                            <input type="text" value="{{ date('Y-m-d', $admin->updated_at) }}" class="form-control form-control-line"
                                   disabled>
                        </div>
                    </div>
                    <div class="form-group">
                        <button class="fcbtn btn btn-success btn-outline btn-1e waves-effect">更新个人信息</button>
                        {!! csrf_field() !!}
                        <a href="/system/admin"
                           class="fcbtn btn btn-info btn-outline btn-1e waves-effect">返回管理员列表</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
@section('js')
    @parent
    <!-- icheck -->
    <script src="{{ asset('plugins/bower_components/icheck/icheck.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/icheck/icheck.init.js') }}"></script>
    <script src="{{ asset('js/jasny-bootstrap.js') }}"></script>
    <!-- jQuery file upload -->
    <script src="{{ asset('plugins/bower_components/dropify/dist/js/dropify.min.js') }}"></script>
    <script>
        $(document).ready(function () {
            // Basic
            $('.dropify').dropify();
        });
    </script>
    <script src="{{ asset('plugins/bower_components/bootstrap-select/bootstrap-select.min.js') }}"
            type="text/javascript"></script>
    <!-- bt-switch -->
    <script src="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.js') }}"></script>
    <script type="text/javascript">
        $(".bt-switch input[type='checkbox'], .bt-switch input[type='radio']").bootstrapSwitch();
        var radioswitch = function () {
            var bt = function () {
                $(".radio-switch").on("switch-change", function () {
                    $(".radio-switch").bootstrapSwitch("toggleRadioState")
                }),
                    $(".radio-switch").on("switch-change", function () {
                        $(".radio-switch").bootstrapSwitch("toggleRadioStateAllowUncheck")
                    }),
                    $(".radio-switch").on("switch-change", function () {
                        $(".radio-switch").bootstrapSwitch("toggleRadioStateAllowUncheck", !1)
                    })
            };
            return {
                init: function () {
                    bt()
                }
            }
        }();
        $(document).ready(function () {
            radioswitch.init()
        });


        $(document).ready(function () {
            $('#editadmin').submit(function (e) {
                e.preventDefault();
                swal({
                        title: "",
                        text: "确定修改么？",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "是的",
                        closeOnConfirm: false
                    },
                    function () {
                        $.ajax({
                            type: "POST",
                            url: '/system/admin/detail/' + $('#adminid').val(),
                            data: $('#editadmin').serialize(),// 你的formid
                            async: false,
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            error: function (err) {
                                for (var j in err.responseJSON) {
                                    err.responseJSON[j].forEach(function (item, index) {
                                        swal(item);
                                    })
                                }
                            },
                            success: function (data) {
                                if (data.status === 1) {
                                    swal(data.message, '', 'success');
                                    $('.confirm').click(function () {
                                        location.reload();
                                    });
                                } else {
                                    swal(data.message);
                                }
                            }
                        });
                    })
            });
        });
    </script>
@endsection